package com.rd.student.jike.class1.sunhao.day02;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;

public class GetlistUtils {


    public static void Glu1(LinkedList linkedList){
        HashMap hashMap = new HashMap();
        int p=1;
        int q;
        for (int i=0;i<linkedList.size();i++){
            q =((Student)linkedList.get(i)).cla;
            if (!(hashMap.containsKey(q))) {
                p=1;
                hashMap.put(q,p);

            }else {
                hashMap.put(q,++p);
            }
        }
        info(hashMap);
    }
    public static void info(HashMap hashMap) {

         Set set = hashMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = hashMap.get(key);
            System.out.println(key + "班"+"：" + value + "人");
        }
    }
    public static void Glu2(LinkedList linkedList,String major){
        HashMap hashMap = new HashMap();
        int p=1;

        for (int i=0;i<linkedList.size();i++){
            major=((Student)linkedList.get(i)).major;
            if (!(hashMap.containsKey(major))) {
                p=1;
                hashMap.put(major,p);

            }else {
                hashMap.put(major,++p);
            }
        }
        info1(hashMap);
    }
    public static void info1(HashMap hashMap) {

        Set set = hashMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = hashMap.get(key);
            System.out.println(key + "专业"+"：" + value + "人");
        }
    }
    public static void Glu3(LinkedList linkedList){
        HashMap hashMap = new HashMap();
        int age;
        int p=1;

        for (int i=0;i<linkedList.size();i++){
            age=((Student)linkedList.get(i)).age;
            if (!(hashMap.containsKey(age))) {
                p=1;
                hashMap.put(age,p);

            }else {
                hashMap.put(age,++p);
            }
        }
        info2(hashMap);
    }
    public static void info2(HashMap hashMap) {

        Set set = hashMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = hashMap.get(key);
            System.out.println(key + "岁"+"：" + value + "人");
        }
    }
    public static void Glu4(LinkedList linkedList){
        LinkedList linkedList1=new LinkedList();
        for (int i=0;i<linkedList.size();i++){
            linkedList1.add(((Student)linkedList.get(i)).name);
        }
        for (int i=0;i<linkedList1.size();i++){
            System.out.println(linkedList1.get(i));
        }
    }
}
